﻿using UnityEditor;
using UnityEngine;

namespace Yoozoo.Core.Timeline
{
    [CustomEditor(typeof(TimelineConstructor))]
    [CanEditMultipleObjects]
    public class TimelineConstructorEditor : UnityEditor.Editor
    {
        
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (GUILayout.Button("一键寻找",GUILayout.Height(20)))
            {
                foreach (var t in targets)
                {
                    TimelineConstructor constructor = t as TimelineConstructor;
                    constructor.FindObjectAvatar(false);
                }
            }

            if (GUILayout.Button("销毁多余组件（AudioListener3D...）"))
            {
                foreach (var t in targets)
                {
                    TimelineConstructor constructor = t as TimelineConstructor;
                    constructor.DestroyErrorComponents();
                }
            }
        
            GUILayout.BeginHorizontal();
            
            TimelineConstructor constructor2 = target as TimelineConstructor;
            if (!constructor2.editorMode)
            {
                if (GUILayout.Button("进入编辑模式", GUILayout.Height(30)))
                {
                    constructor2.ShowObjectAvatar();
                }
            }
            else
            {
                if (GUILayout.Button("退出编辑模式",GUILayout.Height(30)))
                {
                    constructor2.HideObjectAvatar();
                }
            }

            GUILayout.EndHorizontal();
        }
    }
}